Add gdk_pixbuf_new_from_file_at_scale(), which is just like
authorMatthias Clasen <maclas@gmx.de>
Thu, 26 Aug 2004 05:33:13 +0000 (05:33 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 26 Aug 2004 05:33:13 +0000 (05:33 +0000)
Thu Aug 26 01:23:16 2004  Matthias Clasen  <maclas@gmx.de>

* gdk-pixbuf-core.h:
* gdk-pixbuf.symbols:
* gdk-pixbuf-io.c (gdk_pixbuf_new_from_file_at_scale):
Add gdk_pixbuf_new_from_file_at_scale(), which is just
like gdk_pixbuf_new_from_file_at_size(), but optionally
ignores the aspect ratio.  (#136395, Dom  Lachowicz)

docs/reference/ChangeLog
docs/reference/gdk-pixbuf/gdk-pixbuf-sections.txt
gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-core.h
gdk-pixbuf/gdk-pixbuf-io.c
gdk-pixbuf/gdk-pixbuf.symbols

index 920a675680867a177130d4f2122c2b9c057803a9..10d5992bfce2de1fa5dc454b97b3551063fbe013 100644 (file)
@@ -1,3 +1,8 @@
+Thu Aug 26 01:31:42 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gdk-pixbuf/gdk-pixbuf-sections.txt: Add 
+       gdk_pixbuf_new_from_file_at_scale().
+
 2004-08-25  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.5.2 ===
index 2dc26b71eef2cd9eda5bdeaad69b2b05fd493221..0b8f05c239ea6704d9b56ab2fcd08770c3d3e224 100644 (file)
@@ -57,6 +57,7 @@ GdkPixbufDestroyNotify
 <FILE>file-loading</FILE>
 gdk_pixbuf_new_from_file
 gdk_pixbuf_new_from_file_at_size
+gdk_pixbuf_new_from_file_at_scale
 gdk_pixbuf_get_file_info
 </SECTION>
 
index 3717c4329b28ce73ea44d4c5246497c535aeaac0..a2967d28b56f76c9813361fa3a7dc3b96f275bf3 100644 (file)
@@ -1,3 +1,12 @@
+Thu Aug 26 01:23:16 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gdk-pixbuf-core.h: 
+       * gdk-pixbuf.symbols: 
+       * gdk-pixbuf-io.c (gdk_pixbuf_new_from_file_at_scale): 
+       Add gdk_pixbuf_new_from_file_at_scale(), which is just
+       like gdk_pixbuf_new_from_file_at_size(), but optionally
+       ignores the aspect ratio.  (#136395, Dom  Lachowicz)
+
 Wed Aug 25 17:23:23 2004  Manish Singh  <yosh@gimp.org>
 
        * io-gif.c: remove unused set_need_recomposite() function.
index 3110a623805242f0a53e40992758e740f4fc1d30..c0f5668ba294a486f58ef8345b75871fd043c64a 100644 (file)
@@ -122,6 +122,11 @@ GdkPixbuf *gdk_pixbuf_new_from_file_at_size (const char *filename,
                                             int         width, 
                                             int         height,
                                             GError    **error);
+GdkPixbuf *gdk_pixbuf_new_from_file_at_scale (const char *filename,
+                                             int         width, 
+                                             int         height,
+                                             gboolean    keep_aspect_ratio,
+                                             GError    **error);
 
 GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data,
                                     GdkColorspace colorspace,
index 88d223ee44274689090a256684381d0ce7845f7f..b22fc86aa01044bcaa8924b96b7437563ccc3a04 100644 (file)
@@ -868,49 +868,59 @@ size_prepared_cb (GdkPixbufLoader *loader,
                  gpointer         data)
 {
        struct {
-               int width;
-               int height;
+               gint width;
+               gint height;
+               gboolean preserve_aspect_ratio;
        } *info = data;
 
        g_return_if_fail (width > 0 && height > 0);
 
-       if ((double)height * (double)info->width >
-           (double)width * (double)info->height) {
-               width = 0.5 + (double)width * (double)info->height / (double)height;
-               height = info->height;
+       if(info->preserve_aspect_ratio) {
+               if ((double)height * (double)info->width >
+                   (double)width * (double)info->height) {
+                       width = 0.5 + (double)width * (double)info->height / (double)height;
+                       height = info->height;
+               } else {
+                       height = 0.5 + (double)height * (double)info->width / (double)width;
+                       width = info->width;
+               }
        } else {
-               height = 0.5 + (double)height * (double)info->width / (double)width;
                width = info->width;
+               height = info->height;
        }
-
+       
        gdk_pixbuf_loader_set_size (loader, width, height);
 }
 
 /**
- * gdk_pixbuf_new_from_file_at_size:
+ * gdk_pixbuf_new_from_file_at_scale:
  * @filename: Name of file to load.
  * @width: The width the image should have
  * @height: The height the image should have
+ * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
  * @error: Return location for an error
  *
  * Creates a new pixbuf by loading an image from a file.  The file format is
  * detected automatically. If %NULL is returned, then @error will be set.
  * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
- * The image will be scaled to fit in the requested size, preserving its aspect ratio.
+ * The image will be scaled to fit in the requested size, optionally preserving
+ * the image's aspect ratio.
  *
- * Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
- * any of several error conditions occurred:  the file could not be opened,
+ * Return value: A newly-created pixbuf with a reference count of 1, or %NULL 
+ * if any of several error conditions occurred:  the file could not be opened,
  * there was no loader for the file's format, there was not enough memory to
  * allocate the image buffer, or the image file contained invalid data.
  *
- * Since: 2.4
+ * Since: 2.6
  **/
 GdkPixbuf *
-gdk_pixbuf_new_from_file_at_size (const char *filename,
-                                 int         width, 
-                                 int         height,
-                                 GError    **error)
+gdk_pixbuf_new_from_file_at_scale (const char *filename,
+                                  int         width, 
+                                  int         height,
+                                  gboolean    preserve_aspect_ratio,
+                                  GError    **error)
 {
+
        GdkPixbufLoader *loader;
        GdkPixbuf       *pixbuf;
 
@@ -920,6 +930,7 @@ gdk_pixbuf_new_from_file_at_size (const char *filename,
        struct {
                gint width;
                gint height;
+               gboolean preserve_aspect_ratio;
        } info;
 
        g_return_val_if_fail (filename != NULL, NULL);
@@ -943,6 +954,7 @@ gdk_pixbuf_new_from_file_at_size (const char *filename,
 
        info.width = width;
        info.height = height;
+        info.preserve_aspect_ratio = preserve_aspect_ratio;
 
        g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
 
@@ -988,6 +1000,38 @@ gdk_pixbuf_new_from_file_at_size (const char *filename,
        return pixbuf;
 }
 
+/**
+ * gdk_pixbuf_new_from_file_at_size:
+ * @filename: Name of file to load.
+ * @width: The width the image should have
+ * @height: The height the image should have
+ * @error: Return location for an error
+ *
+ * Creates a new pixbuf by loading an image from a file.  The file format is
+ * detected automatically. If %NULL is returned, then @error will be set.
+ * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
+ * The image will be scaled to fit in the requested size, preserving
+ * the image's aspect ratio.
+ *
+ * Return value: A newly-created pixbuf with a reference count of 1, or 
+ * %NULL if any of several error conditions occurred:  the file could not 
+ * be opened, there was no loader for the file's format, there was not 
+ * enough memory to allocate the image buffer, or the image file contained 
+ * invalid data.
+ *
+ * Since: 2.4
+ **/
+GdkPixbuf *
+gdk_pixbuf_new_from_file_at_size (const char *filename,
+                                 int         width, 
+                                 int         height,
+                                 GError    **error)
+{
+       return gdk_pixbuf_new_from_file_at_scale (filename, 
+                                                 width, height, 
+                                                 TRUE, error);
+}
+
 static void
 info_cb (GdkPixbufLoader *loader, 
         int              width,
index f42c960239050ec2c2292c524bef659cb3c38a06..2d14d2360fcb4ac17b914667e4cf381943d7e8c0 100644 (file)
@@ -61,6 +61,7 @@ gdk_pixbuf_new
 gdk_pixbuf_new_from_data
 gdk_pixbuf_new_from_file
 gdk_pixbuf_new_from_file_at_size
+gdk_pixbuf_new_from_file_at_scale
 gdk_pixbuf_new_from_inline
 gdk_pixbuf_new_from_xpm_data
 gdk_pixbuf_new_subpixbuf